//
//  DNHouseModel.m
//  ZKDN
//
//  Created by JKSD on 2019/4/11.
//  Copyright © 2019 Allen. All rights reserved.
//

#import "DNHouseModel.h"

@implementation DNHouseModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName
{
    return @{@"ID": @"id"};
}
+(instancetype)saveWithKeyValues:(id)keyValues{
    DNHouseModel *model = [[DNHouseModel findAllObject] firstObject];
    
    if (!model) {
        model = [[DNHouseModel alloc]init];
        
    }
    NSArray *proNames = [DNHouseModel getProperties][@"name"];
    
    for (NSString *proName in proNames) {
        if([proName isEqualToString:@"id"]){
            id value = [keyValues valueForKey:@"ID"];
            if (value) {
                
                [model setValue:[keyValues valueForKey:@"id"] forKey:@"ID"];
            }
        }
        id value = [keyValues valueForKey:proName];
        if (value) {
            
            [model setValue:[keyValues valueForKey:proName] forKey:proName];
        }
    }
    [model saveOrUpdate];
    return model;
}

+(NSString *)currentUserID{
    
    DNHouseModel *user = [[DNHouseModel findAllObject] firstObject];
    if(user.ID == nil)return @"";
    
    return user.ID;
}




- (NSString *)userId
{
    if(_ID == nil)
    {
        _ID = @"";
    }
    return _ID;
}

+(instancetype)currentUser{
    
    DNHouseModel *user = [[DNHouseModel findAllObject] firstObject];
    
    return user;
}
@end
